
package com.javaleague.sesionUsuario;

import com.javaleague.persistencia.mysql.DAOUpdateMessage;
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author TaixMiguel
 */
public class UpdateMensajeLeido extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
        
        int error = 403;
        if (request.getParameter("idM") != null) {
            HttpSession session = request.getSession(true);
            Usuario user = (Usuario)session.getAttribute("usuario");
            if (user != null) {
                int id = Integer.parseInt(request.getParameter("idM"));

                if (DAOUpdateMessage.marcarLeidoEmail(user.getId(), user.getTokenUser(), id))
                    error = 200;
                else
                    error = 604;
            }
        }        
        response.sendError(error);
    } 
    
    
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        processRequest(request, response);
    }
}